package com.wn.production.web;

import com.wn.common.PageBean;
import com.wn.common.ResponseEntity;
import com.wn.entity.WorkOrder;
import com.wn.production.service.WorkOrderService;
import com.wn.production.vo.WorkOrderVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/production/woc")
@Slf4j
@Validated
public class WorkOrderController {
    @Autowired
    private WorkOrderService workOrderService;
    /**
     * @param workOrder
     * @return com.wn.common.ResponseEntity
     * @ author zc
     * @ date 2022/10/24 19点04分
     * @ Description 需要提供生产计划员,项目,物料编号(物料档案表,指定为半成品物料),工单号,数量,开工日期,计划结束日期,状态(待分配,待执行,已完成)
     */
    @RequestMapping("add")
    public ResponseEntity add( @Validated WorkOrder workOrder) {
        workOrderService.insert(workOrder);
        return ResponseEntity.success;
    }

    @RequestMapping("getByCondition")
    public ResponseEntity getByCondition(@RequestBody WorkOrderVo workOrderVo) {

        PageBean<WorkOrder> pageBean = workOrderService.getByCondition(workOrderVo);
        return new ResponseEntity(pageBean);
    }
    @RequestMapping("getByConditionn")
    public ResponseEntity getByConditionn(@RequestBody WorkOrder workOrder) {
        List<WorkOrder> list= workOrderService.getByConditionn(workOrder);
        return new ResponseEntity(list);
    }
    @RequestMapping("getAll")
    public ResponseEntity getAll(@RequestBody WorkOrderVo workOrderVo) {
        PageBean<WorkOrder> pageBean = workOrderService.getAll(workOrderVo);
        return new ResponseEntity(pageBean);
    }
    @RequestMapping("update")
    public ResponseEntity update(@RequestBody @Validated WorkOrder workOrder) {
        workOrderService.update(workOrder);
        return ResponseEntity.success;
    }
}
